import { formatBytes } from '@/utils/format'

export default function useConfig() {
  const { allRegionOptions } = useRegions()
  const columns = computed(() =>
    buildColumns([
      {
        title: '所属区域',
        dataIndex: 'region_name',
        minWidth: 160,
        render({ record }) {
          return getOptionLabel(record.region_id, allRegionOptions.value)
        },
      },
      {
        title: '镜像名称',
        dataIndex: 'image_name',
        minWidth: 200,
      },
      {
        title: '类型',
        dataIndex: 'image_type',
        minWidth: 160,
        render({ record }) {
          if (Number(record.image_type) === 1)
            return '云服务器'
          if (Number(record.image_type) === 2)
            return '裸金属'
          return '-'
        },
      },
      {
        title: '磁盘格式',
        dataIndex: 'disk_format',
        minWidth: 160,
      },
      {
        title: '大小',
        dataIndex: 'image_size',
        minWidth: 160,
        render({ record }) {
          return formatBytes(record.image_size).toString()
        },
      },
      {
        title: '状态',
        dataIndex: 'image_status',
        minWidth: 130,
        render({ record }) {
          if (record.image_status === 'active')
            return '运行中'
          return '-'
        },
      },
      {
        title: '可见性',
        dataIndex: 'visibility',
        minWidth: 130,
        slotName: 'visibility',
      },
      {
        title: '操作',
        fixed: 'right',
        slotName: 'actions',
        width: 70,
        cellClass: 'actions-cell',
      },
    ]),
  )
  return { columns }
}
